package com.zHan.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zHan.model.dto.SysOperLogQueryDto;
import com.zHan.model.system.SysOperLog;
import com.zHan.system.mapper.SyeOperLogMapper;
import com.zHan.system.service.IOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ClassName: OperLogServiceImpl
 * Description:
 * date: 2023/6/27 0027 16:53
 *
 * @author zHan
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SyeOperLogMapper, SysOperLog> implements IOperLogService {

    @Autowired
    private SyeOperLogMapper operLogMapper;

    /**
     * 记录操作日志
     *
     * @param sysOperLog
     */
    @Override
    public void saveOperLog(SysOperLog sysOperLog) {
        operLogMapper.insert(sysOperLog);
    }

    /**
     * 操作日志分页条件查询
     *
     * @param page
     * @param pageSize
     * @param logQueryVo
     * @return
     */
    public Page<SysOperLog> selectPageQuery(Long page, Long pageSize,
                                            SysOperLogQueryDto logQueryVo) {
        // 创建Page对象
        Page<SysOperLog> pageInfo = new Page<>(page, pageSize);
        // 创建条件构造器
        LambdaQueryWrapper<SysOperLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        // 获得查询参数
        String title = logQueryVo.getTitle();
        String operName = logQueryVo.getOperName();
        String timeBegin = logQueryVo.getCreateTimeBegin();
        String timeEnd = logQueryVo.getCreateTimeEnd();

        // 查询条件
        if (!StringUtils.isEmpty(title)) {
            lambdaQueryWrapper.like(SysOperLog::getTitle, title);
        }
        if (!StringUtils.isEmpty(operName)) {
            lambdaQueryWrapper.like(SysOperLog::getOperName, operName);
        }
        if (!StringUtils.isEmpty(timeBegin)) {
            lambdaQueryWrapper.ge(SysOperLog::getUpdateTime, timeBegin);
        }
        if (!StringUtils.isEmpty(timeEnd)) {
            lambdaQueryWrapper.le(SysOperLog::getUpdateTime, timeEnd);
        }

        // 执行分页方法
        page(pageInfo, lambdaQueryWrapper);

        return pageInfo;
    }
}
